import unittest
import sys
sys.path.append("../main/")
from tables import tablesDatabase
import os.path
from JsonParse import JSONParser
import json

class TestUserDatabaseFunctions(unittest.TestCase):

    def setUp(self):
        fp = open("../../json/jira.json", "r")
        self.parser = JSONParser(fp.read())
        fp = open("../../json/jira.json", "r")
        self.data = json.loads(fp.read())
        self.table = "new"
        self.columns = [["displayName", "TEXT"], ["field", "TEXT"]]
        return

    def test_creation(self):
        database = tablesDatabase("../../databases/tests/u346156.db")
        database.close()
        self.assertTrue(os.path.isfile("../../databases/tests/u346156.db"))
        database = tablesDatabase("../../databases/tests/u346156.db")
        data = self.parser.getItems(["changelog", "histories", 0, ["author", "displayName"], ["items", 0, "field"]], self.data)
        print data
        database.importTable("test", self.columns, data)
        database.importTable(self.table, self.columns, data)
        print database.getDatabase()
        print database.getTable(self.table)
        print database.getTableColumns(self.table)
        print database.getColumn(self.table, "displayName")
        database.destroyTable("test")
        database.destroyTable("new")
        
if __name__ == '__main__':
    unittest.main()
